package com.example.imtoken.room.base

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.imtoken.room.dao.*
import com.example.imtoken.room.schema.*

@Database(
    entities = [AccountSchema::class, AppLoginSchema::class, WalletBackUpSchema::class, WalletCheckedSchema::class, WalletAddressSchema::class, TransactionRecordSchema::class, AddressBookSchema::class],
    version = 1
)
abstract class AppDataBase : RoomDatabase() {
    abstract fun getAccountDao(): AccountDao
    abstract fun getAppLoginDao(): AppLoginDao
    abstract fun getWalletBackUpDao(): WalletBackUpDao
    abstract fun getWalletCheckedDao(): WalletCheckedDao
    abstract fun getWalletAddressDao(): WalletAddressDao
    abstract fun getTransactionRecordDao(): TransactionRecordDao
    abstract fun getAddressBookDao(): AddressBookDao

    companion object {
        private val DB_NAME = "imtoken.db"
        private lateinit var mContext: Context
        val instance by lazy {
            Room.databaseBuilder(
                mContext,
                AppDataBase::class.java,
                DB_NAME
            )
//                .addMigrations(MIGRATION_2_3) //升级数据库操作
                .allowMainThreadQueries().build()
        }

        fun init(mContext: Context) {
            this.mContext = mContext
        }
    }
}